package com.itlong.cloud.controller.system;


import com.itlong.cloud.POJO.DTO.property.PropertyRoleGetPageDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyUserInfoGetPageDTO;
import com.itlong.cloud.POJO.PO.PropertyRolePO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.property.*;
import com.itlong.cloud.abstracts.BaseController;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.annotation.LoggerInfo;
import com.itlong.cloud.constants.LogDescConstant;
import com.itlong.cloud.enumerate.DataStatusEnum;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode.PropertyErrorCodeEnum;
import com.itlong.cloud.equip.property.IPropertyDeviceAuthServiceClient;
import com.itlong.cloud.equip.property.IPropertyEquipServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.user.property.IPropertyHouseHoldDeviceAuthServiceClient;
import com.itlong.cloud.user.property.IPropertyRoleServiceClient;
import com.itlong.cloud.user.property.IPropertyUserServiceClient;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.page.Page;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      物业-系统-菜单管理控制器
 * </desc>
 *
 * @createDate 2017/09/21
 */
@RestController
@RequestMapping("/system/role")
public class PropertyRoleController extends BaseController{

    private static final Logger LOG = LoggerFactory.getLogger(PropertyRoleController.class);
    @Autowired
    IPropertyRoleServiceClient iPropertyRoleServiceClient;

    @Autowired
    IPropertyUserServiceClient iPropertyUserServiceClient;

    @Autowired
    IPropertyEquipServiceClient iPropertyEquipServiceClient;

    @Autowired
    IPropertyHouseHoldDeviceAuthServiceClient iPropertyHouseHoldDeviceAuthServiceClient;

    @Autowired
    IPropertyDeviceAuthServiceClient iPropertyDeviceAuthServiceClient;
    /**
     * <desc>
     *      获取分页列表
     * </desc>
     *
     * @param propertyRoleGetPageDTO 查询参数DTO
     * @return messageVO
     * @author Biao.R
     * @createDate 2017/09/25
     */
    @ResponseBody
    @AuthAccessRequired
    @PostMapping(path = "getPage")
    public Object getPage(PropertyRoleGetPageDTO propertyRoleGetPageDTO){
        MessageVO messageVO;
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyRoleGetPageDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyRoleGetPageDTO.class, request);
            if (propertyRoleGetPageDTO == null /*|| StringUtils.isBlank(propertyRoleGetPageDTO.getGroupId())*/) { // 因为留着旧角色数据要维护，故去掉部门id的校验，可以为空
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            Page<PropertyRoleVO> page=iPropertyRoleServiceClient.getPage(propertyRoleGetPageDTO);
            messageVO=new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),page);
        } catch (Exception e) {
            throw new DataAccessException("【物业_系统_角色getPage】获取分页列表失败",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      添加角色
     * </desc>
     *
     * @param propertyRoleGetPageDTO 角色实体
     * @return messageVO
     * @author Biao.R
     * @createDate 2017/09/25
     */
    @PostMapping(path = "save")
    @ResponseBody
    @AuthAccessRequired
    @LoggerInfo(operateDesc = LogDescConstant.USER_PROPERTY_SAVEROLE_LOG_DESC)
    public Object save(PropertyRoleGetPageDTO propertyRoleGetPageDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyRoleGetPageDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyRoleGetPageDTO.class, request);
            if (propertyRoleGetPageDTO == null || StringUtils.isBlank(propertyRoleGetPageDTO.getRoleName()) || StringUtils.isBlank(propertyRoleGetPageDTO.getGroupId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            Map<String, Object> params = new HashMap<>();
            params.put("roleName", propertyRoleGetPageDTO.getRoleName());
            params.put("projectId", propertyRoleGetPageDTO.getProjectId());
            params.put("mark", "noGroupId");
            List<PropertyRolePO> roleList = iPropertyRoleServiceClient.getByFields(params);
            if (roleList != null && !roleList.isEmpty()) {
                return new MessageVO(PropertyErrorCodeEnum.USER_ROLE_ROLENAME_EXIST.getErrorCode());
            }
            iPropertyRoleServiceClient.save(propertyRoleGetPageDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【物业_系统_角色save】添加资源失败", e);
        }
    }

    /**
     * <desc>
     *      修改角色
     * </desc>
     *
     * @param propertyRoleGetPageDTO 角色实体
     * @return messageVO
     * @author Biao.R
     * @createDate 2017/09/21
     */
    @PostMapping(path = "update")
    @ResponseBody
    @AuthAccessRequired
    @LoggerInfo(operateDesc = LogDescConstant.USER_PROPERTY_UPDATEROLE_LOG_DESC)
    public Object update(PropertyRoleGetPageDTO propertyRoleGetPageDTO){
        MessageVO messageVO;
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyRoleGetPageDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyRoleGetPageDTO.class, request);

            if (propertyRoleGetPageDTO == null || StringUtils.isBlank(propertyRoleGetPageDTO.getRoleName()) || StringUtils.isBlank(propertyRoleGetPageDTO.getGroupId())) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            Map<String, Object> params = new HashMap<>();
            params.put("roleName", propertyRoleGetPageDTO.getRoleName());
            params.put("projectId", propertyRoleGetPageDTO.getProjectId());
            params.put("roleIdNot", propertyRoleGetPageDTO.getRoleId());
            params.put("mark", "noGroupId");
            List<PropertyRolePO> roleList = iPropertyRoleServiceClient.getByFields(params);
            if (roleList != null && !roleList.isEmpty()) {
                return new MessageVO(PropertyErrorCodeEnum.USER_ROLE_ROLENAME_EXIST.getErrorCode());
            }

            Integer result = iPropertyRoleServiceClient.update(propertyRoleGetPageDTO);

            if (result == -1) {
                return new MessageVO(PropertyErrorCodeEnum.USER_ROLE_ROLENAME_EXIST.getErrorCode());
            }
            messageVO=new MessageVO(propertyRoleGetPageDTO.getRoleId(),BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【物业-_系统_角色update】更新资源失败", e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      查询单条角色
     * </desc>
     *
     * @param propertyRolePO 角色实体
     * @return messageVO
     * @author Biao.R
     * @createDate 2017/09/25
     */
    @PostMapping(path = "getOne")
    @ResponseBody
    public Object getOne(PropertyRolePO propertyRolePO){
        MessageVO messageVO;
        try{
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyRolePO = HttpProtocolUtil.parseRequestParamToDTO(PropertyRolePO.class, request);
            propertyRolePO=iPropertyRoleServiceClient.getOne(propertyRolePO);
            messageVO=new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),propertyRolePO);
        }catch (Exception e){
            throw new DataAccessException("【物业_系统_角色getOne】获取单条资源失败",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      删除角色
     * </desc>
     *
     * @param roleIds 角色id数组字符串 ，号分隔
     * @return messageVO
     * @author Biao.R
     * @createDate 2017/09/25
     */
    @PostMapping(path = "delete")
    @ResponseBody
    @LoggerInfo(operateDesc = LogDescConstant.USER_PROPERTY_DELETEROLE_LOG_DESC)
    public Object delete(String roleIds){
        MessageVO messageVO;
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            roleIds = request.getAttribute("roleIds") == null ? null : request.getAttribute("roleIds").toString();
            iPropertyRoleServiceClient.delete(roleIds);
            messageVO=new MessageVO(roleIds,BaseErrorCodeEnum.SUCCESS.getErrorCode());
        }catch(Exception e){
            throw new DataAccessException("【物业_系统_角色delete】删除资源失败",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      启用或禁用
     * </desc>
     *
     * @param propertyRoleGetPageDTO 资源实体
     * @return messageVO
     * @author Biao.R
     * @createDate 2017/09/26
     */
    @PostMapping(path = "banOrUse")
    @ResponseBody
    @AuthAccessRequired
    @LoggerInfo(operateDesc = LogDescConstant.USER_PROPERTY_BANORUSEROLE_LOG_DESC)
    public Object banOrUse(PropertyRoleGetPageDTO propertyRoleGetPageDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyRoleGetPageDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyRoleGetPageDTO.class, request);
            iPropertyRoleServiceClient.update(propertyRoleGetPageDTO);
            return new MessageVO(propertyRoleGetPageDTO.getRoleId(),BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【物业_系统_角色banOrUse】启用或禁用失败", e);
        }
    }

    /**
     * <desc>
     *      角色分配菜单按钮权限前，查询角色菜单和按钮
     *      角色的菜单权限不能超出物业管理员的菜单和按钮权限
     * <desc/>
     * @param   propertyRoleGetPageDTO  物业角色查询对象
     * @return
     * @author Biao.R
     * @createDate 2017/10/26
     */
    @ResponseBody
    @PostMapping(path = "getRoleFunctions")
    public Object getRoleFunctions(PropertyRoleGetPageDTO propertyRoleGetPageDTO) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyRoleGetPageDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyRoleGetPageDTO.class, request);
            if (propertyRoleGetPageDTO == null) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (StringUtils.isBlank(propertyRoleGetPageDTO.getRoleId())) {
                return new MessageVO(PropertyErrorCodeEnum.USER_ROLE_ROLEID_NOT_NULL.getErrorCode());
            }
            List<PropertyParentFunctionVO> roleFunctions = iPropertyRoleServiceClient.getRoleFunctions(propertyRoleGetPageDTO);
            if (roleFunctions != null && !roleFunctions.isEmpty()) {
                //给菜单排序
                for (PropertyParentFunctionVO returnFunction : roleFunctions) {
                    List<PropertyChildFunctionVO> childFunctionList = returnFunction.getChildFunctionList();
                    if (childFunctionList != null && !childFunctionList.isEmpty()) {
                        childFunctionList.sort((PropertyChildFunctionVO fun1, PropertyChildFunctionVO fun2) -> fun2.getOrders().compareTo(fun1.getOrders()));
                        //按钮也需要排序
                        for (PropertyChildFunctionVO propertyChildFunctionVO : childFunctionList) {
                            List<PropertyButtonFunctionVO> buttonFunctionVOS = propertyChildFunctionVO.getChildFunctionList();
                            if (buttonFunctionVOS != null && !buttonFunctionVOS.isEmpty()) {
                                buttonFunctionVOS.sort((PropertyButtonFunctionVO fun1, PropertyButtonFunctionVO fun2) -> fun2.getFunctionId().compareTo(fun2.getFunctionId()));
                            }
                        }
                    }
                }
            }
            String propertyApp = iPropertyRoleServiceClient.getRolePropertyApp(propertyRoleGetPageDTO);
            return new MessageVO(propertyApp, BaseErrorCodeEnum.SUCCESS.getErrorCode(), roleFunctions);
        } catch (Exception e) {
            throw new DataAccessException("【物业_系统_角色】查询角色菜单权限失败", e);
        }
    }


    /**
     * <desc>
     *      保存角色菜单
     * </desc>
     *
     * @param roleId 角色id
     * @param functionIds 资源id 多个,号分隔
     * @param projectId 项目编号
     * @return  messageVO
     * @author Biao.R
     * @createTime 2017/09/26
     */
    @AuthAccessRequired
    @PostMapping(path = "saveRoleFunction")
    @LoggerInfo(operateDesc = LogDescConstant.USER_PROPERTY_SAVEROLEFUNCTIONS_LOG_DESC)
    public Object saveRoleFunction(String roleId,
                                      String projectId,
                                      String functionIds,String propertyApp){
        try{
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            roleId = request.getAttribute("roleId") == null ? null : request.getAttribute("roleId").toString();
            projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
            functionIds = request.getAttribute("functionIds") == null ? null : request.getAttribute("functionIds").toString();
            propertyApp = request.getAttribute("propertyApp") == null ? null : request.getAttribute("propertyApp").toString();
            if(StringUtils.isBlank(roleId)){
                return new MessageVO(PropertyErrorCodeEnum.USER_ROLE_ROLEID_NOT_NULL.getErrorCode());
            }
            iPropertyRoleServiceClient.saveRoleFunction(roleId,functionIds,projectId,propertyApp);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        }catch (Exception e){
            throw new DataAccessException("【物业_系统_角色saveRoleFunction】保存角色菜单失败",e);
        }
    }

    /**
     * <desc>
     *      获取所有角色
     * </desc>
     *
     * @return messageVo
     * @author Biao.R
     * @createDate 2017/09/29
     */
    @PostMapping(path = "getList")
    @ResponseBody
    public Object getList(String projectId, String groupId){
        try{
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
            groupId = request.getAttribute("groupId") == null ? null : request.getAttribute("groupId").toString();
            if (StringUtils.isBlank(projectId)) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_IS_ILLEGAL.getErrorCode());
            }
            if (StringUtils.isBlank(groupId)) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            Map<String, Object> params = new HashMap<>();
            params.put("projectId", projectId);
            params.put("pubType", "0");
            params.put("status", DataStatusEnum.NORMAL.getType());
            params.put("groupId", groupId);
            List<PropertyRolePO> roleList = iPropertyRoleServiceClient.getByFields(params);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),roleList);
        }catch (Exception e){
            throw new DataAccessException("【物业_系统_角色getList】获取所有角色失败",e);
        }
    }

    /**
     * <desc>
     *      查询指定角色所有用户
     * </desc>
     *
     * @param projectId 项目id
     * @param roleId 角色id
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2018/08/15
     */
    @PostMapping(path = "getRoleUser")
    @ResponseBody
    public Object getRoleUser(String projectId,String roleId){
        try{
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
            roleId = request.getAttribute("roleId") == null ? null : request.getAttribute("roleId").toString();
            if (StringUtils.isBlank(projectId) || StringUtils.isBlank(roleId)) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            List<PropertyGetRoleUserVO> propertyGetRoleUserVOS =  iPropertyRoleServiceClient.getRoleUser(projectId,roleId);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),propertyGetRoleUserVOS);
        }catch (Exception e){
            throw new DataAccessException("【物业_系统_角色getRoleUser】获取指定角色所有用户失败",e);
        }
    }

    /**
     * <desc>
     *      获取分配人员列表
     * </desc>
     *
     * @param pageDTO1  查询参数DTO
     * @return
     * @author Biao.R
     * @createDate 2017/10/10
     */
    @PostMapping(path = "getAllotUserPage")
    @ResponseBody
    public Object getAllotUserPage(PropertyUserInfoGetPageDTO pageDTO1){
        try{
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            pageDTO1 = HttpProtocolUtil.parseRequestParamToDTO(PropertyUserInfoGetPageDTO.class, request);
            PropertyUserInfoGetPageDTO pageDTO = pageDTO1;
            Page<PropertyUserInfoGetUserPageVO> page=iPropertyUserServiceClient.getPage(pageDTO);
            List<PropertyUserInfoGetUserPageVO> users =page.getRows();
            //检查是否已拥有该角色
            users.forEach(user -> {
                String roleIds = user.getRoleId();
                if (roleIds != null) {
                    String[] roleIdArr = roleIds.split(",");
                    for (String roleId : roleIdArr) {
                        if (roleId.equals(pageDTO.getAllotRoleId())) {
                            user.setHaveRole("true");
                            break;
                        }
                    }
                }
            });
            page.setRows(users);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),page);
        }catch (Exception e){
            throw new DataAccessException("【物业_系统_角色getAllotUserPage】获取分配人员列表失败",e);
        }
    }


    /**
     * <desc>
     *      保存角色分配的用户
     * </desc>
     *
     * @param roleId    角色id
     * @param allotUsers    需要分配的人员id 多个，号分隔
     * @param userIds 当前列表所有人员id 多个，号分隔
     * @return
     * @author Biao.R
     * @createDate 2017/10/10
     */
    @PostMapping(path = "saveRoleUsers")
    @ResponseBody
    @AuthAccessRequired
    @LoggerInfo(operateDesc = LogDescConstant.USER_PROPERTY_SAVEROLEUSERS_LOG_DESC)
    public Object saveRoleUsers(
            String roleId,
            String allotUsers,
            String userIds) {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            roleId = request.getAttribute("roleId") == null ? null : request.getAttribute("roleId").toString();
            allotUsers = request.getAttribute("allotUsers") == null ? null : request.getAttribute("allotUsers").toString();
            userIds = request.getAttribute("userIds") == null ? null : request.getAttribute("userIds").toString();
            iPropertyRoleServiceClient.saveRoleUsers(roleId, allotUsers, userIds);
            return new MessageVO(String.format("%s|%s|%s",roleId,allotUsers,userIds),BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【物业_系统_角色saveRoleUsers】角色分配用户失败", e);
        }
    }


    /**
     * <desc>
     *      角色绑定设备权限时，查询设备权限分页:暂时不做
     * <desc/>
     *
     * @param propertyRoleEquipAuthGetDTO 设备授权时分页获取设备信息的数据传输对象
     * @return MessageVO 标准格式化响应结果
     * @author Biao.R
     * @createDate 2017/10/10
     */
/*    @PostMapping(path = "/getDeviceAuthPage")
    @ResponseBody
    public Object getDeviceAuthPage(PropertyRoleEquipAuthGetDTO  propertyRoleEquipAuthGetDTO) {
        try {
            //参数合法性判断
            if(propertyRoleEquipAuthGetDTO == null) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            PropertyEquipAuthGetDTO propertyEquipAuthGetDTO = new PropertyEquipAuthGetDTO();
            BeanUtils.copyProperties(propertyRoleEquipAuthGetDTO,propertyEquipAuthGetDTO);
            String userId = propertyRoleEquipAuthGetDTO.getRoleId();
            propertyEquipAuthGetDTO.setUserId(userId);
            if(StringUtils.isBlank(userId)) {
                return new MessageVO(PropertyErrorCodeEnum.APPUSER_USERPROJECTSTATUS_NOT_NULL.getErrorCode());
            }
            String projectId = propertyEquipAuthGetDTO.getProjectId();
            if(StringUtils.isBlank(projectId)) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            Integer deviceType = propertyEquipAuthGetDTO.getDeviceType();

            PropertyEquipTypeEnum equipTypeEnum = PropertyEquipTypeEnum.getByEquipType(deviceType);
            if(equipTypeEnum.getType()==-1){
                return new MessageVO(PropertyErrorCodeEnum.EQUIP_DEVICETYPE_IS_ILLEGAL.getErrorCode());
            }

            //分页获取设备信息
            Page<PropertyEquipSimpleVO> page = iPropertyEquipServiceClient.getEquipAuthByPage(propertyEquipAuthGetDTO);
            if(page == null) {
                return new MessageVO(PropertyErrorCodeEnum.APPUSER_DEVICEAUTH_ERR.getErrorCode());
            }
            //整合返回的设备授权时分页获取设备信息的数据和用户设备权限数据
            List<PropertyEquipSimpleVO> lists = page.getRows();
            //获取用户设备权限
            List<AppUserGetDeviceAuthVO> appUserGetDeviceAuthVOS =
                    iPropertyDeviceAuthServiceClient.getUserDeviceAuth(userId, projectId, deviceType.toString());

            //整合分页查询到的设备数据和用户设备权限数据
           *//* for(PropertyEquipSimpleVO map:lists) {
                for(AppUserGetDeviceAuthVO appUserGetDeviceAuthVO:appUserGetDeviceAuthVOS) {
                    if(map.get("deviceUnique").equals(appUserGetDeviceAuthVO.getDeviceUnique())) {
                        map.put("naturalFloor", appUserGetDeviceAuthVO.getNaturalFloor());
                        map.put("deviceType", appUserGetDeviceAuthVO.getDeviceType());
                        if(appUserGetDeviceAuthVO.getIsChecked() != null) {
                            map.put("isChecked", String.valueOf(appUserGetDeviceAuthVO.getIsChecked()));
                        } else {
                            map.put("isChecked", String.valueOf(PlatformConstants.DEVICEAUTH_ISCHECKED_YET));
                        }
                        lists.set(lists.indexOf(map), map);
                    }
                }
            }*//*
            page.setRows(lists);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), page);
        } catch (Exception e) {
            throw new DataAccessException("【物业_系统_角色】分页查询设备权限失败", e);
        }
    }*/


    /**
     * <desc>
     *      设备授权-更新角色设备权限：暂时不做
     * <desc/>
     *
     * @param loginUserId 用户登录Id
     * @param roleId 角色Id
     * @param projectId 项目Id
     * @param appUserGetDeviceAuths 用户设备权限数据集
     * @return MessageVO 标准格式化响应结果
     * @author Biao.R
     * @createDate 2017/10/10
     */
/*    @LoggerInfo(operateDesc = LogDescConstant.USER_PROPERTY_SAVEROLEEQUIPAUTH_LOG_DESC)
    @RequestMapping(path = "/updateRoleDeviceAuth", method = RequestMethod.POST)
    @ResponseBody
    public Object updateRoleDeviceAuth(
            @RequestParam("loginUserId") String loginUserId,
            @RequestParam("roleId") String roleId,
            @RequestParam("projectId") String projectId,
            @RequestParam("appUserGetDeviceAuths") String appUserGetDeviceAuths) {
        try {
            //参数合法性判断
            if (StringUtils.isBlank(roleId)) {
                return new MessageVO(PropertyErrorCodeEnum.USER_ROLE_ROLEID_NOT_NULL.getErrorCode());
            }
            if (StringUtils.isBlank(projectId)) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            if (StringUtils.isBlank(appUserGetDeviceAuths)) {
                return new MessageVO(PropertyErrorCodeEnum.APPUSER_DEVICEAUTH_NOT_NULL.getErrorCode());
            }
            //解析用户设备权限数据集
            List<AppUserGetDeviceAuthVO> appUserGetDeviceAuthVOS = JSON.parseArray(appUserGetDeviceAuths, AppUserGetDeviceAuthVO.class);
            if (appUserGetDeviceAuthVOS.size() == 0) {
                return new MessageVO(PropertyErrorCodeEnum.APPUSER_DEVICEAUTH_NOT_NULL.getErrorCode());
            }

            //更新源于物业系统的其他类型的用户设备权限
            iPropertyDeviceAuthServiceClient.updateOtherUserDeviceAuth(loginUserId, roleId, projectId,
                    DeviceAuthEnum.DEVICEAUTH_PROPERTY.getType(), appUserGetDeviceAuthVOS);


            //查询该角色下的用户,并更新该角色下用户的权限
            Map<String, Object> params = new HashMap<>();
            params.put("roleId", roleId);
            List<PropertyUserInfoPO> userInfoPOS = iPropertyUserServiceClient.getList(params);
            if (userInfoPOS != null && !userInfoPOS.isEmpty()) {
                for (PropertyUserInfoPO userInfoPO : userInfoPOS) {
                    iPropertyDeviceAuthServiceClient.updateOtherUserDeviceAuth(loginUserId, userInfoPO.getUserId(),
                            projectId, DeviceAuthEnum.DEVICEAUTH_PROPERTY.getType(), appUserGetDeviceAuthVOS);
                }
            }
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException(String.format(
                    "【物业系统_更新用户设备权限_updateUserDeviceAuth()】info:{%s, %s, %s}", roleId, projectId, appUserGetDeviceAuths), e);
        }
    }*/
}
